<?php 
include_once("$config[webroot]/includes/page_utf_class.php");


$sql = "select * from ".SHARELOG." where 1 ";
$page = new Page;
$page->listRows=20;
//分页
if (!$page->__get('totalRows'))
{
	$db->query($sql);
	$page->totalRows = $db->num_rows();
}
$sql .= "  limit ".$page->firstRow.",".$page->listRows;
$db->query($sql);
$de['list']=$db->getRows();
$de['page']=$page->prompt();
$condTemp = $_GET;
unset($condTemp['m']);
unset($condTemp['s']);
$cond = "";
if(count($condTemp)){
	$cond = "&".http_build_query($condTemp);
}


//查询用户信息以及上级信息

foreach($de as &$vos){
    foreach ($vos as $k=>$v){
        $sql = "select name from ".MEMBER." where userid = '".$v['memberId']."'";
        $db->query($sql);
        $userinfo = $db->getRows();
        $vos[$k]['userName'] = $userinfo[0]['name'];
        
        $sql = "select name from ".MEMBER." where userid = '".$v['parentId']."'";
        $db->query($sql);
        $parentInfo = $db->getRows();
        $vos[$k]['parentName'] = $parentInfo[0]['name'];
    }
}


if ($_POST['act']=='export'){
    include_once '../lib/php_excel.php';
    
    $sql = "select * from ".SHARELOG."";
    $db->query($sql);
    $de['list']=$db->getRows();
    
    $listCount = 0;
    foreach($de as &$vos){
        foreach ($vos as $k=>$v){
            $export_data[$listCount]['memberId'] = $v['memberId'];
            $export_data[$listCount]['userName'] = $v['userName'];
            if($v['level'] == 1)
            {
                $export_data[$listCount]['level'] = '首席';
            }elseif ($v['level'] == 2)
            {
                $export_data[$listCount]['level'] = '红人';
            }elseif($v['level'] == 3)
            {
                $export_data[$listCount]['level'] = '吃货';
            }
            $export_data[$listCount]['parentId'] = $v['parentId'];
            $export_data[$listCount]['parentName'] = $v['parentName'];
            $export_data[$listCount]['shareUrl'] = $v['shareUrl'];
            $export_data[$listCount]['shareTime'] = $v['shareTime'];
            
            if($v['shareId'] == 1)
            {
                $export_data[$listCount]['shareId'] = '分享到朋友圈';
            }elseif ($v['shareId'] == 2)
            {
                $export_data[$listCount]['shareId'] = '发送给朋友';
            }elseif($v['shareId'] == 3)
            {
                $export_data[$listCount]['shareId'] = '分享到QQ';
            }else
            {
                $export_data[$listCount]['shareId'] = '分享到微博';
            }
            
            $listCount++;
        }
    }

    $queue[0] = array("会员ID","会员名称","会员等级", "上级ID","上级名称","分享url","分享时间","分享类型");//定义表头
    $export_data = array_merge($queue,$export_data);
    //print_r($export_data);
    $filename =   "分享数据" . date ( "YmdHis" );
    $xls = new Excel_XML ( 'UTF-8', false, '分享数据' );
    $xls->addArray ( $export_data );
    $xls->generateXML ( $filename );
    exit ();
}


$tpl->assign("cond",$cond);
$tpl->assign('de',$de);
$tpl->assign("config",$config);
$tpl->display("share_log_list.htm");
?>